package com.magicalcoder.youyaboot.config;

import org.hibernate.HibernateException;
import org.hibernate.dialect.SQLServer2012Dialect;

import java.sql.Types;
/*自定义方言 因为sqlserver默认把string转varchar 不支持中文，所以我们改成nvarchar*/
public class MySqlServerDialect extends SQLServer2012Dialect {
    public MySqlServerDialect() {
        super();
        registerColumnType( Types.CLOB, "nvarchar(MAX)" );
        registerColumnType( Types.LONGVARCHAR, "nvarchar(MAX)" );
        registerColumnType( Types.VARCHAR, "nvarchar(MAX)" );
        registerColumnType( Types.VARCHAR, 8000, "nvarchar($l)" );//低于8000的varchar统一用nvarchar(length)
        // HHH-8435 fix
        registerColumnType( Types.NCLOB, "nvarchar(MAX)" );
    }
    public String getTypeName(int code, int length, int precision, int scale) throws HibernateException {
        if(code != 2005) {
            return super.getTypeName(code, length, precision, scale);
        } else {
            return "ntext";
        }
    }
}
